<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>日计划</title>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">日计划管理</div>
		</div>
	</div>
	<div class="new-form">
		<div>
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 100px;">内容：</td>
						<td>
							<input class="easyui-textbox" data-options="multiline:true" id="content" name="content"
								style="width: 100%; height: 100px;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">日期：</td>
						<td>
							<input class="easyui-datebox" data-options="validType:'planexist',editable:false"
								id="plandate" name="plandate" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">形象进度：</td>
						<td>
							<input class="easyui-textbox" data-options="validType:['number','percent']" id="percent"
								name="percent" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td class="text-center">
							<label>主计划未完成形象进度：</label>
							<label id="remainpercent"></label>
							<label>%</label>
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align: center;" class="search-input" id="div1">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">保存</a>
			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro =[[${planDaily}]];
	
	$(document).ready(function() {
		getRemainPercent();
		if(currentPro.id != null){
			$("#content").textbox("setValue", currentPro.content);
			$("#percent").textbox("setValue", currentPro.percent);
			$("#plandate").datebox("setValue",formatDate(currentPro.plandate));
			if(currentPro.status != 6){
				document.getElementById('div1').style.display = 'none';
			}
		}
	});
	function savePro() {
		var content = $("#content").textbox('getValue');
		currentPro.content = content;
		var plandate = $("#plandate").datebox('getValue');
		currentPro.plandate = plandate;
		var percent = $("#percent").textbox('getValue');
		currentPro.percent = percent;
		$.ajax({
			type : 'POST',
			url : "../planDailySave.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存日计划', '保存日计划成功', 'success');
				} else {
					$.messager.alert('保存日计划', '保存日计划失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	
	function getRemainPercent(){
		$.ajax({
			type : 'GET',
			url : "../planmain/unfinishpercent?mainid="+currentPro.mainid,
			contentType : "application/json",
			success : function(data) {
				if (data) {
					$("#remainpercent").text(data);
				}
			},
			dataType : "text"
		});
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	
	$.extend($.fn.textbox.defaults.rules, {
		number: {//value值为文本框中的值
			validator: function (value) {
				var reg = /^\d+(\.\d+)?$/;
				return reg.test(value);
			},
			message : "请输入数字"
		},
	    percent:{
	    	validator: function (value, param) {
	    		var percent = $("#remainpercent").text();
	            return parseFloat(value)<=parseFloat(percent);
	 
	        },
	        message: '不能超过剩余形象进度'
	    },
    	planexist:{
	    	validator : function(value, param) {
		    	var data = {};
		    	if(currentPro.id){
		    		data.planid = currentPro.id;
		    	}else{
		    		data.planid= 0;
		    	}
		    	data.plandate = value;
		    	data.mainid = currentPro.mainid;
	    		var res = false;
	    		$.ajax({
					type: 'POST',
					async : false,
					url: '../check/plandate',
					data: data,
					success: function(data) {
						res= data.success;
					},
					dataType: "json"
				});
				return res;
	        },
	        message : '已存在日计划'
   		}
    });
</script>
</html>